package com.project.util;

import com.project.bean.UserBean;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 登陆拦截器
 */
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //从session中，得到登陆用户信息
        UserBean user = (UserBean)request.getSession().getAttribute("loginUser");
        System.out.println("user="+user);
        if(user != null){//用户已经登陆
            return true;
        }
//        response.sendRedirect("/login.html?errorInfo=noGrade");
        response.getWriter().print("noGrade");
        return false;
    }
}
